package com.example.appkcsj.slice;

import com.example.appkcsj.DAO.FamilyDao;
import com.example.appkcsj.DAO.FamilyDaoImpl;
import com.example.appkcsj.ResourceTable;
import com.example.appkcsj.dbutils.DBUtils;
import com.example.appkcsj.entity.Family;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.TextField;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class seventhAbilitySlice extends AbilitySlice {
    private final static HiLogLabel HI_LOG_LABEL=
            new HiLogLabel(HiLog.LOG_APP,0x00201,"seventhAbilitySlice");
    private TextField t;
    private Button b;
    private FamilyDao familyDao;
    TextField textField;
//    private DBUtils1 dbUtils1;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_seventh);

        familyDao = new FamilyDaoImpl(this);
//        dbUtils1=new DBUtils1(seventhAbilitySlice.this);
        b = (Button) findComponentById(ResourceTable.Id_but10);
        t = (TextField) findComponentById(ResourceTable.Id_field12);

        textField = (TextField) findComponentById(ResourceTable.Id_textField);
//        if(intent!=null){
//            String name1=intent.getStringParam("name1");
//            String name=intent.getStringParam("name");
//            String phone=intent.getStringParam("phone");
//            String age=intent.getStringParam("age");
//            String address=intent.getStringParam("address");
//            String birth=intent.getStringParam("birth");
//            Family family=new Family(name1,name,phone,age,address,birth);
//            dbUtils1.insertFamily(family);
//        }
        b.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
//                Family family=dbUtils1.queryOneFamily();
                Family family = familyDao.queryByName(t.getText());

                if (family != null) {
                    textField.setText("姓名：" + family.getName1()+"\n"+"\n"
                                     +"家谱名：" + family.getName()+"\n"+"\n"
                            +"联系方式：" + family.getPhone()+"\n"+"\n"
                            +"年龄：" + family.getAge()+"\n"+"\n"
                            +"地址：" + family.getAddress()+"\n"+"\n"
                            +"生日：" + family.getBirth());

                    //HiLog.info(HI_LOG_LABEL,"查询数据"+family);
                } else {
                    textField.setText("       查无此人");
                }
            }
        });
    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
